package com.example.myapplication

import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        val linearLayout = LinearLayout(this)
        linearLayout.orientation = LinearLayout.VERTICAL

        val textView = TextView(this)
        textView.text=getString(R.string.hello)

        val imageView = ImageView(this)
        imageView.setImageResource(R.drawable.flag)

        val button = Button(this)
        button.text=getString(R.string.click_me)

        linearLayout.addView(textView)
        linearLayout.addView(imageView)
        linearLayout.addView(button)

        setContentView(linearLayout)

//        setContentView(R.layout.activity_main)
//        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main))
        ViewCompat.setOnApplyWindowInsetsListener(linearLayout)
        { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        button.setOnClickListener {
          textView.text= getString(R.string.i_an_clicked)
      }
//        val button = findViewById<Button>(R.id.button)
//        button.setOnClickListener {
//            val textView=findViewById<TextView>(R.id.textView)
//            textView.text= getString(R.string.i_an_clicked)
//        }
    }
}